﻿Ext.namespace("Swfu");
Ext.namespace("Swfu.BackMgr");


Swfu.BackMgr.AnnualMgr = Ext.extend(Ext.grid.GridPanel, {
    initComponent: function () {
        var ddlDeptVaca = new Ext.form.TreeField({
            id: 'treeDeptVaca', name: 'treeDeptVaca',
            dataUrl: '/dept.mvc/DeptTreeByEmp',
            syncParams: 'controllerName=Annual',
            listHeight: 250, width: 150
        });
        var sm = new Ext.grid.CheckboxSelectionModel({ singleSelect: true });
        var fm = Ext.form;

        var cm = new Ext.grid.ColumnModel([
            {
                header: "部门", width: 150,
                dataIndex: 'dep'
            }, {
                header: "姓名", width: 100,
                dataIndex: 'name'
            }, {
                header: "首次工作日期", width: 150,
                dataIndex: 'fristwork',
                editor: new Ext.grid.GridEditor(new Ext.form.DateField({ format: "Y-m-d" })),
                renderer: function (value) {
                    if (value != '') {
                        return new Date(Date.parse(value.replace(/\-/g, "/"))).format("Y-m-d");
                    }
                }
            }, {
                header: "入职日期", width: 130,
                dataIndex: 'trialDate',
                editor: new Ext.grid.GridEditor(new Ext.form.DateField({ format: "Y-m-d" })),
                renderer: function (value) {
                    if (value != '')
                        return new Date(Date.parse(value.replace(/\-/g, "/"))).format("Y-m-d");
                }
            }, {
                header: "总工龄", width: 80,
                dataIndex: 'sumworkdays'
            }, {
                header: "是否满一年",
                dataIndex: 'onemoreyear'
            }, {
                header: "年假数",
                dataIndex: 'annualwork'
            }, {
                header: "已休天数",
                dataIndex: 'hadused',
                renderer: function (value) {
                    if (value == "")
                        return 0;
                    else
                        return value;
                }
            }
		]);
        var reader = new Ext.data.JsonReader({
            totalProperty: 'totalCount', //分页使用
            root: 'data',
            autoLoad: true,
            fields: [{
                name: 'dep'
            }, {
                name: 'name'
            }, {
                name: 'fristwork'
            }, {
                name: 'trialDate'
            }, {
                name: 'sumworkdays'
            }, {
                name: 'onemoreyear'
            }, {
                name: 'annualwork'
            }, {
                name: 'hadused'
            }]
        });
        var ds = new Ext.data.Store({
            scopte: this,
            id: 'AnnualDS',
            url: '/Annual.mvc/Find',
            reader: reader
        });
        ds.on('beforeload', function (thiz, options) {
            Ext.apply(thiz.baseParams, { idStr: Ext.getCmp('treeDeptVaca').getValue() });
        });

        Ext.apply(this, {
            id: 'AnnualMgr',
            plain: true,
            layout: 'fit',
            border: false,
            cm: cm,
            sm: sm,
            frame: true,
            store: ds,
            loadMask: true,
            tbar: ['->', {
                xtype: 'tbtext',
                text: '部门:'
            }, ddlDeptVaca, {
                xtype: 'tbtext',
                text: '姓名:'
            }, {
                xtype: 'textfield',
                name: 'txtName',
                id: 'txtName',
                emptyText: '人名的一或几个字',
                blankText: '人名的一或几个字',
                anchor: '100%'
            }, '-', {
                text: "查询",
                iconCls: 'icon-search',
                handler: function () {
                    ds.reload();
                }
            }],

            //分页
            bbar: new Ext.PagingToolbar({
                pageSize: 20,
                store: ds,
                displayInfo: true,
                displayMsg: '显示第 {0} 条到 {1} 条记录，共 {2} 条',
                emptyMsg: '无记录',
                hidden: false
            })
        });
        Swfu.BackMgr.AnnualMgr.superclass.initComponent.apply(this, arguments);
        ds.load({ params: { start: 0, limit: 20} });
        ds.on('beforeload', function (thiz, options) {
            Ext.apply(thiz.baseParams, { name: Ext.getCmp('txtName').getValue() });
        });
    }
});

Ext.reg('AnnualMgr', Swfu.BackMgr.AnnualMgr);